/*
 * 
 *
 *
 */
package com.hboxs.asl.dao.impl;

import com.hboxs.asl.dao.CategoryDao;
import com.hboxs.asl.entity.Category;
import org.springframework.stereotype.Repository;

import javax.persistence.FlushModeType;
import javax.persistence.NoResultException;

/**
 * Dao - 总分类
 */
@Repository("categoryDaoImpl")
public class CategoryDaoImpl extends BaseDaoImpl<Category, Long> implements CategoryDao {

    @Override
    public Category findByName(String name) {
        if (name == null) {
            return null;
        }
        try {
            String jpql = "select category from Category category where lower(category.name) = lower(:name)";
            return entityManager.createQuery(jpql, Category.class).setFlushMode(FlushModeType.COMMIT).setParameter("name", name).getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
    }
}
